package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.BedDto;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bed")
@Api(tags = "床位管理相关接口")
public class BedController extends BaseController {

    @Autowired
    private BedService bedService;

    @GetMapping("/read/room/{roomId}")
    @ApiOperation(value = "根据房间id查询床位", notes = "传入房间id")
    public ResponseResult<List<BedVo>> readBedByRoomId(
            @ApiParam(value = "房间ID", required = true) @PathVariable("roomId") Long roomId) {
        List<BedVo> beds = bedService.getBedsByRoomId(roomId);
        return success(beds);
    }
    @ApiOperation(value = "新增床位信息", notes = "提供床位相关信息创建床位")
    @PostMapping("/create")
    public ResponseResult createBed(@ApiParam(value = "床位DTO", required = true) @RequestBody BedDto bedDto) {
        bedService.addBed(bedDto);
        return ResponseResult.success();
    }

    @ApiOperation(value = "根据床位ID查询床位信息", notes = "传入床位ID")
    @GetMapping("/read/{id}")
    public ResponseResult readBed(@ApiParam(value = "床位ID", required = true) @PathVariable Long id) {
        BedVo bedVo = bedService.getBedById(id);
        return ResponseResult.success(bedVo);
    }

    @ApiOperation(value = "更新床位信息", notes = "根据床位ID更新床位信息")

    @PutMapping("/update")
    public ResponseResult updateBed(@ApiParam(value = "床位DTO", required = true) @RequestBody BedDto bed) {
        bedService.updateBed(bed);
        return ResponseResult.success();
    }

    @ApiOperation(value = "删除床位", notes = "根据床位ID删除床位")

    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteBed(@ApiParam(value = "床位ID", required = true) @PathVariable Long id) {
        bedService.deleteBed(id);
        return ResponseResult.success();
    }
}